package cn.hiapi.shopkeeper.service.activity;

import cn.hiapi.interfaces.DispatchContext;
import cn.hiapi.shopkeeper.enums.ActivityType;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author AdinZ
 * @date 2022/12/13 0:53
 */
@Component
public class ActivityFactory {
    private final DispatchContext dispatchContext;

    public ActivityFactory(DispatchContext dispatchContext) {
        this.dispatchContext = dispatchContext;

    }

    public AbsActivityService get(ActivityType type) {
        Optional<AbsActivityService> optional = this.dispatchContext.getServiceList(AbsActivityService.class).stream().filter(e -> e.getActivityType() == type).findFirst();
        if (optional.isPresent()) return optional.get();
        else return null;
    }


}
